package leetcode_jz_offer;

import java.util.Arrays;

/**
 * @author 美女
 * @date 2022/08/31 01:32
 **/

/**
 * https://blog.csdn.net/weixin_39478524/article/details/120790150?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-120790150-blog-104294248.pc_relevant_multi_platform_featuressortv2dupreplace&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-120790150-blog-104294248.pc_relevant_multi_platform_featuressortv2dupreplace&utm_relevant_index=2
 * n个骰子「点数和」的范围为[n,6n] ，数量为6n−n+1=5n+1种
 */
public class Num60_n个骰子的点数 {
    public  double[] dicesProbability(int n) {
        double[] dp = new double[6];
        Arrays.fill(dp, 1.0 / 6.0);//初始化dp数组，当一个骰子时出现的点数及概率
        for (int i = 2; i <= n; i++) {//从两个骰子开始遍历
            double[] temp = new double[5 * i + 1];//当有i个骰子时，就有5i+1种可能
            for (int j = 0; j < dp.length; j++) {//遍历每种骰子和的可能
                for (int k = 0; k < 6; k++) {//将当前的概率加入到i+1个骰子的情况
                    temp[j + k] += dp[j] / 6.0;
                }
            }
            dp = temp;
        }
        return dp;
    }

//    public static void main(String[] args) {
//        dicesProbability(2);
//    }
}